#include"Tcpserver.hpp"
#include"protocol.hpp"
#include"Calculator.hpp"

void User(const char* agrv)
{
    std::cout<<"User should: "<< agrv <<" port"<<std::endl;
    exit(USER_ERR);
}

int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        User(argv[0]);
    }
    uint16_t port = std::stoi(argv[1]);
    
    std::unique_ptr<CalNet> Cal = std::make_unique<CalNet>();
    
    std::unique_ptr<protocol> ptl = std::make_unique<protocol>([&Cal](Request& req)->Respond{
        return Cal->Calculator(req);
    });

    std::unique_ptr<Tcpserver> tcpser = std::make_unique<Tcpserver>(port,[&ptl](std::shared_ptr<TcpSocket> stcp,Inetaddr& addr){
            ptl->GetRequest(stcp);
    });

    tcpser->Start();


    return 0;
}

